<template>
	<view class="bodyWrap" :class="{'flexBox':isFlex}">
		<template v-if="isFlex">
			<view class="my-header"><slot name="header"/></view>
			<scroll-view class="my-main" @scrolltolower="loadingMore" scroll-y="true">
				<slot/>
				<uni-load-more :status="status" v-if="showLoading" />
			</scroll-view>
			<view class="my-footer"><slot name="footer"/></view>
		</template>
		<slot v-else/>
	</view>
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed,watch} from 'vue'
	import {onLoad,onShow} from '@dcloudio/uni-app'
	import { useStore } from 'vuex'
	import {setStorage,getStorage} from '@/utils/common.js'
	import {login,getMemberInfo} from '@/api/index.js'
	//import cFooter from "@/components/cFooter/cFooter.vue"
	export default defineComponent({
		components:{
			//cFooter
		},
		props:{
			isFlex:{
				type:Boolean,
				default:false
			},
			status:String,
			showLoading:{
				type:Boolean,
				default:true
			},
		},
		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				userInfo:computed(()=>store.state.base.userInfo),
			})
			
			// watch(()=>props.status,(newData,oldData) =>{
			// 	console
			// })
			
			onMounted(()=>{
				// var pages = getCurrentPages() // 获取栈实例
				// let currentRoute  = pages[pages.length-1].route; // 获取当前页面路由
				// let currentPage = pages[pages.length-1]['$page']['fullPath'] //当前页面路径(带参数)
				// console.log("TTYY:",currentRoute,currentPage)
				if(getStorage('token')){ // 已经登陆，获取用户信息
					getMemberInfo().then(res =>{
						if(res.code == 0){
							store.commit('base/set_userInfo',res.data)
						}else{
							setStorage('token','') // 清空token
						}
					})
				}else{ // 为登陆，提示登陆
					uni.showModal({
						title: '提示',
						content: '未登录，请使用当前微信登录！',
						showCancel:false,
						success: async function (res) {
							if (res.confirm) {
								uni.reLaunch({
								 	url:'/pages/login/login'
							 	})
							} else if (res.cancel) {
								//console.log('用户点击取消');
							}
						}
					});
				}

			})
			const loadingMore = ()=>{
				console.log("-----loadingMore,加载更多----")
				context.emit('loadMore')
			}
			
			return {
				...toRefs(state),
				loadingMore
			}
		}
	})
</script>

<style lang="scss">
	.bodyWrap{
		box-sizing: border-box;
		width: 750rpx;
		color: #000;
		/* padding: 0 0 110rpx 0; */
		padding: 0;
		&.flexBox{
			display: flex;
			flex-flow: column;
			position: fixed;
			z-index: 900;
			height: 100%;
			width: 100%;
			.my-main{
				flex: 1;
				overflow: hidden;
			}
		}
	}
</style>
